package com.eyas.business.service;

import com.eyas.business.model.jdbcEntity.table.AdminInfo;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import static com.eyas.core.jdbc.utils.CommonJdbcUtils.commonJdbcUtils;

/**
 * @Auther: 王龙龙
 * @Date: 2019/2/21 15:37
 * @Description:
 */
@Service
public class TestServiceImpl implements TestService {

    @Override
    public void test() {
        //insert 测试成功
        AdminInfo adminInfo = new AdminInfo();
        adminInfo.setAddtime(new Date());
        adminInfo.setLoginname("wll2");
        adminInfo.setPassword("123456");
        adminInfo.setSex("1");
        adminInfo.setTelephone("18669710235");
        adminInfo.setUsername("王龙龙");
        adminInfo.setValidflag("1");
        int nums = commonJdbcUtils.insert(adminInfo);//insert后生成的id
        System.out.println("insert nums----------------------:"+nums);
        System.out.println("new row id--------------------:"+adminInfo.getAdminnid());

        //update测试成功
//        AdminInfo adminInfo2 = commonJdbcUtils.queryObject("select * from admininfo where adminnid=?",AdminInfo.class,newid);
        adminInfo.setTelephone("123456");
        try {
            adminInfo.setAddtime(new SimpleDateFormat("yyyyMMdd HH:mm:ss").parse("20180101 23:59:50"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        commonJdbcUtils.update(adminInfo);

        //delete测试成功
//        AdminInfo adminInfo3 = commonJdbcUtils.queryObject("select * from admininfo where adminnid=?",AdminInfo.class,newid);
        commonJdbcUtils.delete(adminInfo);


        System.out.println("----------------------------"+commonJdbcUtils.queryObject("select count(1) from admininfo",Integer.class));
    }
}
